#!/bin/bash

# Updates Heimer version in all build and packaging scripts. 
# Must be run in the project root.

VERSION_MAJOR=$1
VERSION_MINOR=$2
VERSION_PATCH=$3

if [[ ! $1 || ! $2 || ! $3 ]]; then
    echo "Usage: $0 VERSION_MAJOR VERSION_MINOR VERSION_PATCH"
    exit 1
fi

FILE=CMakeLists.txt
echo "Updating ${FILE} .."
sed -i "s/^set(APPLICATION_VERSION_MAJOR.*/set(APPLICATION_VERSION_MAJOR ${VERSION_MAJOR})/" ${FILE} || exit 1
sed -i "s/^set(APPLICATION_VERSION_MINOR.*/set(APPLICATION_VERSION_MINOR ${VERSION_MINOR})/" ${FILE} || exit 1
sed -i "s/^set(APPLICATION_VERSION_PATCH.*/set(APPLICATION_VERSION_PATCH ${VERSION_PATCH})/" ${FILE} || exit 1

for FILE in snapcraft.yaml scripts/build-app-image scripts/build-archive scripts/build-windows-zip; do
    echo "Updating ${FILE} .."
    sed -i -E "s/[0-9]+\.[0-9]+\.[0-9]+/$VERSION_MAJOR.$VERSION_MINOR.$VERSION_PATCH/g" ${FILE} || exit 1
done

git diff

echo "Done."

